using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIWinDialog : MonoBehaviour
{
	public delegate void WinDialogDelegate();

	public GameObject dialog;

	public GameObject winDialogCareer;

	public GameObject winDialogLeague;

	public UILabel header;

	public List<UISprite> stars = new List<UISprite>();

	public UILabel dominate;

	public UILabel opponentName;

	public UISprite opponentFlag;

	public UILabel careerText;

	public UILabel leagueText;

	public UILabel okText;

	public UILabel leadScore;

	public UILabel leadMessage;

	public UILabel leadWonScore;

	public UILabel countryPoints;

	public GameObject countryPointsGameObject;

	public GameObject shareButton;

	public UILabel shareLabel;

	private int startScore;

	private int endScore;

	private float time;

	private float duration;

	private bool animateScoreActive;

	private UILabel fadeOutLabel;

	private UILabel fadeInLabel;

	private bool activateCrossFadeLabels;

	private float crossTime;

	private float crossFadeDuration;

	private float crossInitialDelay;

	private float crossDelay;

	protected WinDialogDelegate onOk;

	protected string shareTitle;

	protected string shareSubtitle;

	protected string shareText;

	protected bool shareIsGroupPassed;

	protected void Show(GameObject dialogObj)
	{
		dialog.SetActive(true);
		winDialogCareer.SetActive(dialogObj == winDialogCareer);
		winDialogLeague.SetActive(dialogObj == winDialogLeague);
	}

	public void HideShareButton()
	{
		shareButton.SetActive(false);
	}

	public void ShowShareButton(string title, string subtitle, string text, bool isGroupPassed = false)
	{
		if (!GGFacebook.instance.IsAvailable())
		{
			HideShareButton();
			return;
		}
		shareIsGroupPassed = isGroupPassed;
		shareTitle = title;
		shareSubtitle = subtitle;
		shareText = text;
		shareLabel.text = GGFormat.RandomFrom("Share This!", "Let Friends Know!", "Brag!", "Share");
		shareButton.SetActive(true);
	}

	public void ShowCountryScore(int countryScore)
	{
		if (countryScore <= 0)
		{
			countryPointsGameObject.SetActive(false);
			return;
		}
		countryPointsGameObject.SetActive(true);
		countryPoints.text = "Country Points: +" + countryScore;
	}

	public void animateScore(int from, int to, float duration, float delay)
	{
		this.duration = duration;
		startScore = from;
		endScore = to;
		UITools.ChangeText(leadScore, from + " Exp");
		StartCoroutine(DoAnimateScore(from != to, delay));
	}

	private IEnumerator DoAnimateScore(bool animate, float delay)
	{
		yield return new WaitForSeconds(delay);
		animateScoreActive = animate;
	}

	private void Update()
	{
		if (animateScoreActive)
		{
			time += Time.deltaTime;
			float num = time / duration;
			int num2 = (int)Mathf.Lerp(startScore, endScore, num);
			UITools.ChangeText(leadScore, num2 + " Exp");
			if (num > 1f)
			{
				animateScoreActive = false;
				float num3 = 1.5f;
				leadScore.cachedTransform.localScale = new Vector3(num3, num3, 1f);
				TweenScale.Begin(leadScore.cachedGameObject, 0.2f, Vector3.one);
				activateCrossFadeLabels = true;
				crossInitialDelay = 0.5f;
				crossDelay = 1.5f;
				crossFadeDuration = 0.5f;
				fadeInLabel = leadMessage;
				fadeOutLabel = leadScore;
			}
		}
		if (activateCrossFadeLabels)
		{
			if (fadeInLabel == leadMessage && crossTime == 0f)
			{
				fadeInLabel.text = GGFormat.RandomFrom("Leaderboards", "World Rank", "World Position", "Compare your Score!");
			}
			crossTime += Time.deltaTime;
			float t = (crossTime - crossInitialDelay) / crossFadeDuration;
			float num4 = Mathf.Lerp(0f, 1f, t);
			fadeInLabel.alpha = num4;
			fadeOutLabel.alpha = 1f - num4;
			if (crossTime > crossInitialDelay + crossFadeDuration + crossDelay)
			{
				crossTime = 0f;
				UILabel uILabel = fadeInLabel;
				fadeInLabel = fadeOutLabel;
				fadeOutLabel = uILabel;
			}
		}
	}

	private IEnumerator ShowStars(int numStars)
	{
		foreach (UISprite star2 in stars)
		{
			star2.color = Color.black;
		}
		bool isWin = numStars > 0;
		float duration = 0.15f;
		float delay = ((!isWin) ? 0.05f : 0.3f);
		yield return new WaitForSeconds(delay);
		int starsCount = ((!isWin) ? 3 : numStars);
		for (int i = 0; i < starsCount; i++)
		{
			UISprite star = stars[i];
			if (i < numStars)
			{
				star.color = Color.white;
				star.cachedTransform.localScale = new Vector3(2f, 2f, 1f);
			}
			else
			{
				star.color = Color.black;
				star.cachedTransform.localScale = new Vector3(1.3f, 1.3f, 1f);
			}
			TweenScale.Begin(star.cachedGameObject, duration, Vector3.one);
			yield return new WaitForSeconds(duration + delay);
		}
		if (numStars >= 3)
		{
			dominate.cachedGameObject.SetActive(true);
			dominate.cachedTransform.localScale = new Vector3(2f, 2f, 1f);
			Color color = dominate.color;
			color.a = 0f;
			dominate.color = color;
			TweenScale.Begin(dominate.cachedGameObject, duration, Vector3.one);
			TweenAlpha.Begin(dominate.cachedGameObject, duration, 1f);
		}
	}

	public void OnShare()
	{
		GGFacebook.instance.showShareDialog("Real Table Tennis", shareTitle, shareSubtitle, shareText, GGSupportMenu.instance.appUrl(ConfigBase.instance.rateProvider, true));
	}

	public void OnOk()
	{
		dialog.SetActive(false);
		if (onOk != null)
		{
			onOk();
		}
	}

	public void OnLeaderboard()
	{
	}
}
